package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.Parent;
import com.wuseguang.springcloud.entity.QuestionnaireUsersAnswer;
import com.wuseguang.springcloud.service.*;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 学生端
 * </p>
 *
 * @author
 * @since 2020-06-03
 */
@RestController
@RequestMapping("/jurisdiction")
public class ParentController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private ActivityService activityServiceImpl;
    @Autowired
    private AttendanceNoticeService attendanceNoticeServiceImpl;
    @Autowired
    private AttendService attendServiceImpl;
    @Autowired
    private CampusSceneryService service;
    @Autowired
    private ImportAndExportSchoolsService importAndExportSchoolsServiceImpl;
    @Autowired
    private StudentEvaluationScoreRecordService studentEvaluationScoreRecordServiceImpl;
    @Autowired
    private QuestionnaireService questionnaireServiceImpl;
    @Autowired
    private NoticeSeeService noticeSeeServiceImpl;
    @Autowired
    private ParentService parentServiceImpl;
    @Autowired
    private StudentsLeaveSchoolService studentsLeaveSchoolServiceImpl;
    @Autowired
    private OrderService orderServiceImpl;
    @Autowired
    private CommodityService commodityServiceImpl;

    /**
     * 家长查询学生活动（家长端）
     *
     * @param request
     * @param studentId 学生id
     * @param type      查询类型 0未报名，1已报名
     * @param indexNo   页码
     * @param rows      每页显示数量
     * @return
     */
    @RequestMapping("/findSignedUpActivity")
    public Result findSignedUpActivity(RequestParameterWrapper request,
                                       @RequestParam(value = "studentId") Integer studentId,
                                       @RequestParam(value = "type", required = false, defaultValue = "0") Integer type,
                                       @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                       @RequestParam(value = "rows", required = false, defaultValue = "10") Integer rows) {
        logger.info("家长查询学生活动");
        return activityServiceImpl.findSignedUpActivity(studentId, type, indexNo, rows);
    }

    /**
     * 活动报名或者取消
     *
     * @param request
     * @param studentId 学生id
     * @param id        活动id
     * @param type      0 取消报名，1报名
     * @return
     */
    @RequestMapping("/activitySignUpOrCancel")
    public Result activitySignUpOrCancel(RequestParameterWrapper request,
                                         @RequestParam(value = "studentId") String studentId,
                                         @RequestParam(value = "id") Integer id,
                                         @RequestParam(value = "type") Integer type) {
        logger.info("活动报名或者取消");
        return activityServiceImpl.activitySignUpOrCancel(studentId, id, type);
    }


    /**
     * 查询学生的班牌通知 家长端
     *
     * @param studentId
     * @return
     */
    @RequestMapping("/findStudentNotice")
    public Result findStudentNotice(RequestParameterWrapper request,
                                    @RequestParam(value = "studentId") Integer studentId) {

        logger.info("查询学生的班牌通知");

        return attendanceNoticeServiceImpl.findStudentNotice(studentId);
    }


    /**
     * 家长查询学生的考勤通知 家长端
     *
     * @return
     */
    @RequestMapping("/findStudentAttendanceNotice")
    public Result findStudentAttendanceNotice(RequestParameterWrapper request,
                                              @RequestParam(value = "studentId") Integer studentId) {
        logger.info("家长查询学生的考勤通知");
        return attendanceNoticeServiceImpl.findStudentAttendanceNotice(studentId);
    }

    /**
     * 根据学生id查询考勤信息（家长端）
     *
     * @param request
     * @param id
     * @param dateTime
     * @return
     */
    @RequestMapping("/findAttendByStudentId")
    public Result findAttendByStudentId(RequestParameterWrapper request,
                                        @RequestParam(value = "id") String id,
                                        @RequestParam(value = "dateTime", required = false) String dateTime) {
        logger.info("根据学生查询学生考勤");
        return attendServiceImpl.findAttendByStudentId(id, dateTime);
    }

    /**
     * 根据学生id查询考勤信息（家长端）
     *
     * @param id
     * @param dateTime
     * @return
     */
    @RequestMapping("/queryAttendByStudentId")
    public Result queryAttendByStudentId(
            @RequestParam(value = "id") String id,
            @RequestParam(value = "dateTime", required = false) String dateTime) {
        logger.info("根据学生查询学生考勤");
        //return new Result(attendServiceImpl.queryAttendByStudentId(id, dateTime));
        return new Result(attendServiceImpl.queryAttendByStudentId2(id, dateTime));
    }

    /**
     * @描述 家长端查询通知
     * @创建人 zm
     * @创建时间 2020/4/27
     */
    @RequestMapping("/queryStudentNoticeList")
    public Result queryStudentNoticeList(@RequestParam(value = "studentId") Integer studentId,
                                         @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                         @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        return service.queryStudentNoticeList(studentId, indexNo, rows);
    }

    /**
     * @描述 家长端查询图片
     * @创建人 zm
     * @创建时间 2020/4/27
     */
    @RequestMapping("/queryStudentPictureList")
    public Result queryStudentPictureList(@RequestParam(value = "studentId") Integer studentId,
                                          @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                          @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        return service.queryStudentPictureList(studentId, indexNo, rows);
    }


    /**
     * @描述 家长端查询视频
     * @创建人 zm
     * @创建时间 2020/4/27
     */
    @RequestMapping("/queryStudentVideoList")
    public Result queryStudentVideoList(@RequestParam(value = "studentId") Integer studentId,
                                        @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                        @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        return service.queryStudentVideoList(studentId, indexNo, rows);
    }


    /**
     * 家长端查询学生进出校
     *
     * @param request
     * @param id      学生id
     * @return
     */
    @RequestMapping("/findStudentInAndOutByStudentId")
    public Result findStudentInAndOutByStudentId(RequestParameterWrapper request,
                                                 @RequestParam(value = "id") Integer id) {

        logger.info("查询学生进出校信息");
        return importAndExportSchoolsServiceImpl.findStudentInAndOutByStudentId(id);
    }

    /**
     * 查询班级任课教师（家长端小程序）
     *
     * @param request
     * @param classId
     * @return
     */
    @RequestMapping("/findClassTeacher")
    public Result findClassTeacher(RequestParameterWrapper request,
                                   @RequestParam(value = "classId") Integer classId) {
        logger.info("查询班级的所有任课老师");
        return studentEvaluationScoreRecordServiceImpl.findClassTeacher(classId);
    }

    /**
     * 查询个人表现 (家长端小程序)
     *
     * @param request
     * @param studentId 学生id
     * @param findType  0本周,1上周,2本月,3自定义
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @RequestMapping("/findPersonalPerformance")
    public Result findPersonalPerformance(RequestParameterWrapper request,
                                          @RequestParam(value = "studentId", required = false) Integer studentId,
                                          @RequestParam(value = "findType", required = false, defaultValue = "0") Integer findType,
                                          @RequestParam(value = "startTime", required = false) String startTime,
                                          @RequestParam(value = "endTime", required = false) String endTime,
                                          @RequestParam(value = "teacherId", required = false) Integer teacherId) {
        logger.info("查询个人表现,studentId={},teacherId={}", studentId, teacherId);
        return studentEvaluationScoreRecordServiceImpl.findPersonalPerformance(studentId, findType, startTime, endTime, teacherId);
    }

    /**
     * 家长端查询问卷调查
     *
     * @param request
     * @param studentId 学生id
     * @return
     */
    @RequestMapping("/findParentQuestionnaire")
    public Result findParentQuestionnaire(RequestParameterWrapper request,
                                          @RequestParam(value = "studentId") Integer studentId,
                                          @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                          @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        logger.info("家长端查询问卷调查");

        return questionnaireServiceImpl.findParentQuestionnaire(studentId, indexNo, rows);
    }

    /**
     * 添加问卷调查信息
     *
     * @param request
     * @param questionnaireUsersAnswer
     * @return
     */
    @RequestMapping("/addQuestionnaireUsersAnswer")
    public Result addQuestionnaireUsersAnswer(RequestParameterWrapper request, @RequestBody QuestionnaireUsersAnswer questionnaireUsersAnswer) {

        logger.info("添加问卷调查信息");

        return questionnaireServiceImpl.addQuestionnaireUsersAnswer(questionnaireUsersAnswer);
    }


    /**
     * 家长查询活动详情（家长端）
     *
     * @param request
     * @param id      活动id
     * @return
     */
    @RequestMapping("/findActivityDetails")
    public Result findActivityDetails(RequestParameterWrapper request,
                                      @RequestParam(value = "id") Integer id,
                                      @RequestParam(value = "studentId") Integer studentId) {
        logger.info("家长查询活动详情");
        return activityServiceImpl.findActivityDetails(id, studentId);
    }

    /**
     * 查询学校当天的放学打卡
     *
     * @param request
     * @param studentId 学生id
     * @return
     */
    @RequestMapping("/findNowLeaveSchoolClockIn")
    public Result findNowLeaveSchoolClockIn(RequestParameterWrapper request,
                                            @RequestParam(value = "studentId") Integer studentId) {
        logger.info("查询学校当天的放学打卡");
        return studentsLeaveSchoolServiceImpl.findNowLeaveSchoolClockIn(studentId);
    }

    /**
     * 查询学校当月的打卡记录
     *
     * @param request
     * @param studentId 学生id
     * @return
     */
    @RequestMapping("/findSameMonthClockIn")
    public Result findSameMonthClockIn(RequestParameterWrapper request,
                                       @RequestParam(value = "studentId") Integer studentId,
                                       @RequestParam(value = "findDate", required = false) String findDate) {
        logger.info("查询学校当月的打卡记录");
        return studentsLeaveSchoolServiceImpl.findSameMonthClockIn(studentId, findDate);
    }

    /**
     * 学生打卡
     *
     * @param request
     * @param id      当天打卡记录id
     * @return
     */
    @RequestMapping("/parentClockIn")
    public Result parentClockIn(RequestParameterWrapper request,
                                @RequestParam(value = "id") Integer id) {
        logger.info("家长打卡");
        return studentsLeaveSchoolServiceImpl.parentClockIn(id);
    }

    /**
     * 查询未查看的通知
     *
     * @param request
     * @param studentId 学生id
     * @return
     */
    @RequestMapping("/findNoticeSee")
    public Result findNoticeSee(RequestParameterWrapper request,
                                @RequestParam(value = "studentId") Integer studentId) {
        return noticeSeeServiceImpl.findNoticeSee(studentId);
    }

    /**
     * 告知查看通知
     *
     * @param request
     * @param studentId      学生id
     * @param jurisdictionId 权限id
     * @return
     */
    @RequestMapping("/informAndCheckNoticeSee")
    public Result informAndCheckNoticeSee(RequestParameterWrapper request,
                                          @RequestParam(value = "studentId") Integer studentId,
                                          @RequestParam(value = "jurisdictionId") Integer jurisdictionId) {
        return noticeSeeServiceImpl.informAndCheckNoticeSee(studentId, jurisdictionId);
    }

    /**
     * 查询家长信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/findParent")
    public Result findParent(RequestParameterWrapper request) {
        //获取家长id
        String parentId = request.getParam("parentId");
        return parentServiceImpl.findParent(parentId);
    }

    /**
     * 修改家长信息
     *
     * @param request
     * @param parent  家长
     * @return
     */
    @RequestMapping("/updateParent")
    public Result updateParent(RequestParameterWrapper request, Parent parent) {
        return parentServiceImpl.updateParent(parent);
    }

    /**
     * 家长购买商品
     * @param request
     * @param commodityId  商品id
     * @return
     */
    @RequestMapping("/parentsOrder")
    public Result parentsOrder(RequestParameterWrapper request,
                               @RequestParam("commodityId") Integer commodityId){
        //家长id
       String  userId = request.getParam("parentId");
       logger.info("家长下订单");
       return orderServiceImpl.parentsOrder(commodityId,userId);
    }

    /**
     * 查询商品
     * @param request
     * @return
     */
    @RequestMapping("/findCommodity")
    public Result findCommodity(RequestParameterWrapper request){
        logger.info("查询商品");
        return commodityServiceImpl.findCommodity();
    }
}
